﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

using Mang24k99.Business.Dissertation;
using Mang24k99.Model.Dissertation;
using System.Collections.Generic;
using Castle.ActiveRecord;

namespace Mang24k99.Web.Dissertation.ChildNews
{
    public partial class List : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            ShowColumn();//显示加载过的新闻栏目
            ViewState["OnlineUserNumber"] = "007";
            try
            {
                selectWeb.SelectedValue = Request["webID"].ToString();
                selectWeb.Enabled = false;
                ViewState["DissNumber"] = Request["ID"].ToString();
                ViewState["AddNewsDisID"] = Request["AddNewsDisID"].ToString();
                //selectDisseratation.Visible = false;
                fx168Dis.Visible = false;
                //bindNews.Visible = false;
                int iNumber=int.Parse(ViewState["DissNumber"].ToString());
                if (iNumber < 6 && iNumber>0)
                    selectDisseratation.SelectedIndex = iNumber;
            }
            catch{
                ViewState["AddNewsDisID"] = "";
                if(selectWeb.SelectedValue=="1"&&selectDisseratation.SelectedValue=="0")
                    ViewState["DissNumber"] = "0";
                else
                    ViewState["DissNumber"] = "1";
            }      //用来标识有几个专题进入选子新闻
            if (!IsPostBack)
            {

                SpecialWeb.Text = Request["webID"].ToString() == "1" ? "FX168" : "24K99";
                BindDisseratation();
                BindDisseratationNews(DateTime.MinValue, DateTime.MinValue, 0, NewsPager.PageSize);
            }
        }

        /// <summary>
        /// 显示加载过的新闻栏目
        /// </summary>
        private void ShowColumn()
        {
            ColumnList.Items.Clear();
            string[] colID = columnIDs.Value.Split('+');
            ColumnList.Items.Add(new ListItem("已选择栏目", "0"));
            for (int x = 0; x < colID.Length - 1; x++)
            {
                string val = BColumnsTable.Find(int.Parse(colID[x])).ColumnName;
                ColumnList.Items.Add(new ListItem(val, colID[x]));
            }
        }

        /// <summary>
        /// 绑定专题
        /// ViewState["DissNumber"] 0:前三个专题;1-5分别为五个专题;大于25为预上线专题
        /// </summary>
        private void BindDisseratation()
        {
            string webID = selectWeb.SelectedValue;// SpecialWeb.Text == "FX168" ? "1" : "2";

            if (ViewState["DissNumber"].ToString() == "0")//前三个专题
            {
                IList<Dissert> dissOnline = BDissertations.FindDissertations(int.Parse(webID), true);
                string disCode = "123450";
                foreach (Dissert aDissOnline in dissOnline)
                {
                    if (aDissOnline.Number == 1)
                    {
                        disTitle1.Text = StandartTitle(aDissOnline.Name);
                        disID1.Value = aDissOnline.ID;
                    }
                    else if (aDissOnline.Number == 2)
                    {
                        disTitle2.Text = StandartTitle(aDissOnline.Name);
                        disID2.Value = aDissOnline.ID;
                    }
                    else if (aDissOnline.Number == 3)
                    {
                        disTitle3.Text = StandartTitle(aDissOnline.Name);
                        disID3.Value = aDissOnline.ID;
                    }
                    if (aDissOnline.Number<6)
                       disCode = disCode.Replace(aDissOnline.Number.ToString(), "");
                }
                if(disCode!="0")
                {
                    bool b24k99 = false;
                    IList<Dissert> Online = BDissertations.FindDissertations(2, true);
                    if (Online != null)
                    {
                        foreach (Dissert aDissOnline in Online)
                        {
                            if (aDissOnline.Number==1)
                            {
                                fx168Dis.Visible = false;
                                selectWeb.SelectedIndex = 1;
                                ViewState["DissNumber"] = "1";
                                oneDiss.Text = StandartTitle(aDissOnline.Name);
                                oneHiddenField.Value = aDissOnline.ID;
                                DisTitleName.Text = GetDisTitle(aDissOnline.Number.ToString());
                                b24k99 = true;
                                break;
                            }
                        }
                    }
                    if (!b24k99)
                        Common.MessageBox.ShowAndRedirect(this,"请先选择五个专题上线,再进行专题子新闻维护!","../List.aspx");
                }
            }
            else if (int.Parse(ViewState["DissNumber"].ToString())==26)//预上线专题
            {
                fx168Dis.Visible = false;
                MColumnToNewsTable aCol = MColumnToNewsTable.Find(long.Parse(ViewState["AddNewsDisID"].ToString()));
                willDiss.Text = StandartTitle(aCol.NewsTitle);
                willHiddenField.Value = ViewState["AddNewsDisID"].ToString();
            }
            else//ViewState["DissNumber"].ToString() :1->5
            {
                IList<Dissert> dissOnline = BDissertations.FindDissertations(int.Parse(webID), true);

                foreach (Dissert aDissOnline in dissOnline)
                {
                    if (aDissOnline.Number.ToString() == ViewState["DissNumber"].ToString())
                    {
                        oneDiss.Text = StandartTitle(aDissOnline.Name);
                        oneHiddenField.Value = aDissOnline.ID;
                        DisTitleName.Text = GetDisTitle(aDissOnline.Number.ToString());
                    }
                }
            }
        }

        protected void selectWeb_SelectedIndexChanged(object sender, EventArgs e)
        {
            SpecialWeb.Text = selectWeb.SelectedItem.Text;
            if (SpecialWeb.Text == "24K99") //没有专题选择下拉框
            {
                ViewState["DissNumber"] = "1";
                bool bOnline = false;
                IList<MDissertations> aDis=MDissertations.Find("DissertationNumber", 1);
                if (aDis != null)
                {
                    if (aDis[0].DissertationWeb == 2)
                    {
                        ViewState["AddNewsDisID"] = 1;
                        fx168Dis.Visible = false;
                        bOnline = true;
                    }
                }
                if (!bOnline)
                    Common.MessageBox.ShowAndRedirect(this, "暂无上线专题!", "List.aspx");
            }
            else
                fx168Dis.Visible = true;
            SpecialWeb.Text = selectWeb.SelectedValue.ToString() == "1" ? "FX168" : "24K99";
            BindDisseratation();
            BindDisseratationNews(DateTime.MinValue, DateTime.MinValue,0,NewsPager.PageSize);
        }

        /// <summary>
        /// 改变专题个数
        /// </summary>
        protected void selectDisseratation_SelectedIndexChanged(object sender, EventArgs e)
        {
            ViewState["DissNumber"] = selectDisseratation.SelectedValue;
            BindDisseratation();
            BindDisseratationNews(DateTime.MinValue, DateTime.MinValue, 0, NewsPager.PageSize);
        }

        /// <summary>
        /// 绑定新闻
        /// </summary>
        /// <param name="start">开始记录数</param>
        /// <param name="end">结束记录数</param>
        private void BindDisseratationNews(DateTime sTime,DateTime eTime,int start,int end)
        {
            int iCount = 0;
            string colID=string.Empty;
            if(columnIDs.Value.Length>0)
                colID = columnIDs.Value.Substring(0, columnIDs.Value.Length - 1).Replace('+', ',');

            Array mNews = BColumnToNewsTable.GetTopNews(sTime, eTime, start, out iCount, end, colID);
            DataTable disInfo = new DataTable();
            disInfo.Columns.Add(new DataColumn("NewsTitle", typeof(string)));
            disInfo.Columns.Add(new DataColumn("NewsID", typeof(long)));
            disInfo.Columns.Add(new DataColumn("LastUpdateTime", typeof(long)));
            if(mNews!=null)
            {
                object[] news = (object[])mNews;
                for (int i = 0; i < news.Length; i++)
                {
                    object[] aNews = (object[])news[i];
                    DataRow dr = disInfo.NewRow();
                    dr[0] = aNews[1].ToString();
                    dr[1] = long.Parse(aNews[0].ToString());
                    dr[2] = long.Parse(aNews[2].ToString());
                    disInfo.Rows.Add(dr);
                }
            }
            if (!string.IsNullOrEmpty(columnIDs.Value))//如果需要按栏目查询
            {
                DataTable newDt = disInfo.Clone();//过滤符合所选栏目的记录
                for (int i = 0; i < disInfo.Rows.Count; i++)
                {
                    IList<MColumnToNewsTable> aNews = MColumnToNewsTable.Find("NewsID", disInfo.Rows[i]["NewsID"]);
                    if (aNews != null && aNews.Count > 0)
                    {
                        for (int k = 0; k < aNews.Count; k++)
                        {
                            if (columnIDs.Value.IndexOf(aNews[k].ColumnID.ToString()) > -1)
                            {
                                DataRow dr = newDt.NewRow();
                                dr[0] = disInfo.Rows[i][0].ToString();
                                dr[1] = long.Parse(disInfo.Rows[i][1].ToString());
                                dr[2] = long.Parse(disInfo.Rows[i][2].ToString());
                                newDt.Rows.Add(dr);
                            }
                        }
                    }
                }
                NewsPager.RecordCount = newDt.Rows.Count ;
                disAddNews.DataSource = newDt;
                disAddNews.DataBind();
            }
            else
            {
                NewsPager.RecordCount = iCount;
                disAddNews.DataSource = disInfo;
                disAddNews.DataBind();
            }
        }

        /// <summary>
        /// 绑定专题
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void OK_Click(object sender, EventArgs e)
        {
            int iItem = disAddNews.Items.Count;//新闻条数
            int iDissCount = 1; //专题数
            try
            {
                if (ViewState["DissNumber"].ToString() == "0")
                    iDissCount = 3;
                for (int i = 0; i < iItem; i++)
                {
                    string newsID = ((HiddenField)disAddNews.Items[i].FindControl("newsID")).Value;
                    for (int x = 1; x <= iDissCount * 4; x++)
                    {
                        CheckBox cb = (CheckBox)disAddNews.Items[i].FindControl("cbNews" + x);
                        if (cb.Checked)
                        {
                            long recordID; 
                            MDissertationToNews aDisNews = new MDissertationToNews();
                            if (x < 5)
                            {//如果是参考文件,存在删除的情况,???
                                //MDissertationToNews aDisNews = new MDissertationToNews();
                                aDisNews.NewsID = long.Parse(newsID);
                                if (ViewState["DissNumber"].ToString() == "0") //三个专题
                                {
                                    aDisNews.Dissertation =MDissertations.Find(int.Parse(disID1.Value));
                                    recordID = BDissertationToNews.ExsitNews(newsID, disID1.Value,x);
                                }
                                else if (int.Parse(ViewState["DissNumber"].ToString()) == 26)//预上线专题
                                {
                                    aDisNews.Dissertation = MDissertations.Find(int.Parse(ViewState["AddNewsDisID"].ToString()));
                                    recordID = BDissertationToNews.ExsitNews(newsID, willHiddenField.Value,x);
                                }
                                else
                                {
                                    aDisNews.Dissertation = MDissertations.Find(int.Parse(oneHiddenField.Value));
                                    recordID = BDissertationToNews.ExsitNews(newsID, oneHiddenField.Value,x);
                                }

                                aDisNews.DissertationSubType = x;
                                aDisNews.BDeleted = 1;
                                if (recordID == 0)       //不存在该子新闻
                                    aDisNews.Create();
                                else
                                {
                                    aDisNews.RecordID = recordID;
                                    aDisNews.Update();
                                }
                            }
                            else if (x > 4 && x < 9)
                            {
                                //MDissertationToNews aDisNews = new MDissertationToNews();
                                aDisNews.NewsID = long.Parse(newsID);
                                aDisNews.DissertationSubType = x - 4;
                                aDisNews.BDeleted = 1;
                                aDisNews.Dissertation = MDissertations.Find(int.Parse(disID2.Value));
                                //aDisNews.Create();
                                recordID = BDissertationToNews.ExsitNews(newsID, disID2.Value,x);
                                if (recordID == 0)
                                    aDisNews.Create();
                                else
                                {
                                    aDisNews.RecordID = recordID;
                                    aDisNews.Update();
                                }
                            }
                            else if (x > 8 && x < 13)
                            {
                                //MDissertationToNews aDisNews = new MDissertationToNews();
                                aDisNews.NewsID = long.Parse(newsID);
                                aDisNews.DissertationSubType = x - 8;
                                aDisNews.BDeleted = 1;
                                aDisNews.Dissertation = MDissertations.Find(int.Parse(disID3.Value));
                                //aDisNews.Create();
                                recordID = BDissertationToNews.ExsitNews(newsID, disID3.Value,x);
                                if (recordID == 0)
                                    aDisNews.Create();
                                else
                                {
                                    aDisNews.RecordID = recordID;
                                    aDisNews.Update();
                                }
                            }
                            //更新该专题有子新闻和更新用户号
                            MDissertations aDis = aDisNews.Dissertation;
                            aDis.LastUpdaterID = int.Parse(ViewState["OnlineUserNumber"].ToString());
                            aDis.DissertationNews = 1;
                            aDis.Update();
                        }
                        else
                        {
                            long recordID;
                            MDissertationToNews aDisNews = new MDissertationToNews();
                            if (x < 5)
                            {//如果是参考文件,存在删除的情况,???
                                //MDissertationToNews aDisNews = new MDissertationToNews();
                                aDisNews.NewsID = long.Parse(newsID);
                                if (ViewState["DissNumber"].ToString() == "0") //三个专题
                                {
                                    aDisNews.Dissertation = MDissertations.Find(int.Parse(disID1.Value));
                                    recordID = BDissertationToNews.ExsitNews(newsID, disID1.Value, x);
                                }
                                else if (int.Parse(ViewState["DissNumber"].ToString()) == 26)//预上线专题
                                {
                                    aDisNews.Dissertation = MDissertations.Find(int.Parse(ViewState["AddNewsDisID"].ToString()));
                                    recordID = BDissertationToNews.ExsitNews(newsID, willHiddenField.Value, x);
                                }
                                else
                                {
                                    aDisNews.Dissertation = MDissertations.Find(int.Parse(oneHiddenField.Value));
                                    recordID = BDissertationToNews.ExsitNews(newsID, oneHiddenField.Value, x);
                                }

                                aDisNews.DissertationSubType = x;
                                aDisNews.BDeleted = 0;
                                if (recordID != 0)      //不存在该子新闻                                   
                                {
                                    aDisNews.RecordID = recordID;
                                    aDisNews.Update();
                                    //aDisNews.Delete();
                                }

                            }
                            else if (x > 4 && x < 9)
                            {
                                //MDissertationToNews aDisNews = new MDissertationToNews();
                                aDisNews.NewsID = long.Parse(newsID);
                                aDisNews.DissertationSubType = x - 4;
                                aDisNews.BDeleted = 1;
                                aDisNews.Dissertation = MDissertations.Find(int.Parse(disID2.Value));
                                //aDisNews.Create();
                                recordID = BDissertationToNews.ExsitNews(newsID, disID2.Value, x);
                                if (recordID != 0)      //不存在该子新闻                                   
                                {
                                    aDisNews.RecordID = recordID;
                                    aDisNews.Update();
                                    //aDisNews.Delete();
                                }
                            }
                            else if (x > 8 && x < 13)
                            {
                                //MDissertationToNews aDisNews = new MDissertationToNews();
                                aDisNews.NewsID = long.Parse(newsID);
                                aDisNews.DissertationSubType = x - 8;
                                aDisNews.BDeleted = 1;
                                aDisNews.Dissertation = MDissertations.Find(int.Parse(disID3.Value));
                                //aDisNews.Create();
                                recordID = BDissertationToNews.ExsitNews(newsID, disID3.Value, x);
                                if (recordID != 0)      //不存在该子新闻                                   
                                {
                                    aDisNews.RecordID = recordID;
                                    aDisNews.Update();
                                    //aDisNews.Delete();
                                }
                            }
                            //更新该专题有子新闻和更新用户号
                            //MDissertations aDis = aDisNews.Dissertation;
                            //aDis.LastUpdaterID = int.Parse(ViewState["OnlineUserNumber"].ToString());
                            //aDis.DissertationNews = 1;
                            //aDis.Update();
                        }
                        




                    }
                }
                Common.MessageBox.ShowAndRedirect(this, "子新闻选择成功!", "../List.aspx?WEBID="+selectWeb.SelectedValue+"&PageIndex=1");
            }
            catch { Common.MessageBox.Show(this,"子新闻添加失败,刷新重试!"); }
        }

        /// <summary>
        /// 专题查询
        /// </summary>
        protected void Search_Click(object sender, EventArgs e)
        {
            SearchNews();
        }

        /// <summary>
        /// 查询新闻
        /// </summary>
        private void SearchNews()
        {
            if (!string.IsNullOrEmpty(startTime.Text) && !string.IsNullOrEmpty(endTime.Text) && Convert.ToDateTime(startTime.Text) > Convert.ToDateTime(endTime.Text))
            {
                Common.MessageBox.Show(this, "请选择专题上线时间!");
                return;
            }
            DateTime sTime = string.IsNullOrEmpty(startTime.Text) ? (new DateTime(1900, 12, 12)) : Convert.ToDateTime(startTime.Text);
            DateTime eTime = string.IsNullOrEmpty(endTime.Text) ? DateTime.Now.AddDays(1) : Convert.ToDateTime(endTime.Text).AddDays(1);

            string webID = selectWeb.SelectedValue;
            int disIDs = 1; //默认是24K99的专题查询;
            if (int.Parse(ViewState["DissNumber"].ToString()) == 26)
                disIDs = 1;
            else if (webID == "1" && selectDisseratation.Visible)
                disIDs = int.Parse(selectDisseratation.SelectedValue);

            bool bCheck = bindNews.Checked;
            DataTable disInfo = new DataTable();
            disInfo.Columns.Add(new DataColumn("NewsTitle", typeof(string)));
            disInfo.Columns.Add(new DataColumn("NewsID", typeof(string)));
            disInfo.Columns.Add(new DataColumn("LastUpdateTime", typeof(long)));

            //ViewState["DissNumber"] = selectDisseratation.SelectedValue;
            if (bCheck)//查询已经进行绑定子新闻
            {
                string showDisId = string.Empty;
                if (ViewState["DissNumber"].ToString() == "0")//三个专题
                    showDisId = disID1.Value + "+" + disID2.Value + "+" + disID3.Value;
                else if (int.Parse(ViewState["DissNumber"].ToString()) == 26)//预上线专题
                    showDisId = willHiddenField.Value;
                else//一个专题
                    showDisId = oneHiddenField.Value;

                string[] showDisids = showDisId.Split('+');
                for (int i = 0; i < showDisids.Length; i++)
                {
                    using (new SessionScope())
                    {
                        MDissertations aDissertation = MDissertations.Find(int.Parse(showDisids[i]));
                        IList<MDissertationToNews> aDisNews = aDissertation.DissertationToNews;//该专题绑定的子新闻
                        if (aDisNews != null && aDisNews.Count > 0)
                        {
                            foreach (MDissertationToNews anew in aDisNews)
                            {   //if (anew.UpdateTime > sTime && anew.UpdateTime < eTime)
                                DataRow disNewDr = disInfo.NewRow();
                                disNewDr[1] = anew.NewsID.ToString();
                                if (disInfo.Select("NewsID=" + disNewDr[1]).Length == 0)
                                {
                                    IList<MColumnToNewsTable> aColumnNews = MColumnToNewsTable.Find("NewsID", anew.NewsID);//, webKey);

                                    for(int y=0;y<aColumnNews.Count;y++)
                                    {
                                        if (aColumnNews[y].LastUpdateTime > long.Parse(sTime.ToString("yyyyMMddHHmmss")) && aColumnNews[y].LastUpdateTime < long.Parse(eTime.ToString("yyyyMMddHHmmss")))
                                        {
                                            if (!string.IsNullOrEmpty(columnIDs.Value) && columnIDs.Value.IndexOf(aColumnNews[y].ColumnID.ToString()) < 0)
                                            { }
                                            else{
                                                disNewDr[0] = aColumnNews[y].NewsTitle;
                                                disNewDr[2] = aColumnNews[y].LastUpdateTime;
                                                disInfo.Rows.Add(disNewDr);
                                                break;
                                            }
                                        }
                                    }
                                    
                                }
                            }
                        }
                    }
                }
                DataTable bindDt = disInfo.Clone();
                if (disInfo != null && disInfo.Rows.Count>0)
                {
                    DataRow[] orderRow = disInfo.Select("1=1", "LastUpdateTime desc");
                    for (int k = 0; k < orderRow.Length; k++)
                    {
                        DataRow dr = bindDt.NewRow();
                        dr[0] = orderRow[k][0].ToString();
                        dr[1] = orderRow[k][1].ToString();
                        dr[2] = long.Parse(orderRow[k][2].ToString());
                        bindDt.Rows.Add(dr);
                    }
                }
                NewsPager.RecordCount = bindDt.Rows.Count;
                disAddNews.DataSource = bindDt;
                disAddNews.DataBind();
            }
            else
                BindDisseratationNews(sTime, eTime, 0, NewsPager.PageSize);
        }

        protected void disAddNews_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            //if (bindNews.Checked)
            //{
                if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
                {
                    //int disIDs = 1;   //默认是24K99的专题查询;-专题号
                    //if (ViewState["DissNumber"].ToString() != "6"&&selectWeb.SelectedValue == "1")
                    //    disIDs = int.Parse(selectDisseratation.SelectedValue);
                    string hfID = ((HiddenField)e.Item.FindControl("newsID")).Value;
                    if (ViewState["DissNumber"].ToString() == "0")
                    {
                        MDissertationToNews anews1 = BDissertationToNews.Find(hfID, disID1.Value);
                        if (anews1 != null)
                            ((CheckBox)e.Item.FindControl("cbNews" + anews1.DissertationSubType.ToString())).Checked = true;
                        MDissertationToNews anews2 = BDissertationToNews.Find(hfID, disID2.Value);
                        if (anews2 != null)
                            ((CheckBox)e.Item.FindControl("cbNews" + (anews2.DissertationSubType + 4).ToString())).Checked = true;
                        MDissertationToNews anews3 = BDissertationToNews.Find(hfID, disID3.Value);
                        if (anews3 != null)
                            ((CheckBox)e.Item.FindControl("cbNews" + (anews3.DissertationSubType + 8).ToString())).Checked = true;
                    }
                    else if (int.Parse(ViewState["DissNumber"].ToString()) == 26)
                    {
                        MDissertationToNews anews = BDissertationToNews.Find(hfID, willHiddenField.Value);
                        if (anews != null)
                            ((CheckBox)e.Item.FindControl("cbNews" + anews.DissertationSubType.ToString())).Checked = true;
                    }
                    else
                    {
                        MDissertationToNews anews = BDissertationToNews.Find(hfID, oneHiddenField.Value);
                        if (anews != null)
                            ((CheckBox)e.Item.FindControl("cbNews" + anews.DissertationSubType.ToString())).Checked = true;
                    }
                }
            //}
        }

        ///// <summary>
        ///// 标识专题
        ///// </summary>
        ///// <param name="id">专题位置</param>
        ///// <returns></returns>
        //private string GetDisTitle(string id)
        //{
        //    switch (id)
        //    {
        //        case "1":
        //            id = "专题一";
        //            break;
        //        case "2":
        //            id = "专题二";
        //            break;
        //        case "3":
        //            id = "专题三";
        //            break;
        //        case "4":
        //            id = "专题四";
        //            break;
        //        case "5":
        //            id = "专题五";
        //            break;
        //    }
        //    return id;
        //}

        /// <summary>
        /// 标识专题
        /// </summary>
        /// <param name="id">专题位置</param>
        /// <returns></returns>
        private string GetDisTitle(string id)
        {
            string[] number = new string[] { "一", "二", "三", "四", "五", "六", "七", "八", "九", "十", 
                "十一", "十二", "十三", "十四", "十五", "十六", "十七", "十八", "十九", "二十", 
                "二十一", "二十二", "二十三", "二十四", "二十五" };
            return "专题" + number[int.Parse(id) - 1];
        }


        /// <summary>
        /// 格式化时间
        /// </summary>
        /// <param name="time"></param>
        /// <returns></returns>
        protected string StandardTime(string time)
        {
            return time.Substring(0, time.Length - 2).Insert(10, ":").Insert(8, " ").Insert(6, "-").Insert(4, "-");
        }

        protected string StandartTitle(string title)
        {
            return title.Length > 10 ? title.Substring(0, 10) + "..." : title;
        }

        /// <summary>
        /// 翻页绑定数据
        /// </summary>
        protected void NewsPager_PageChanged(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(startTime.Text) && !string.IsNullOrEmpty(endTime.Text) && Convert.ToDateTime(startTime.Text) > Convert.ToDateTime(endTime.Text))
            {
                Common.MessageBox.Show(this, "请选择正确的专题上线时间!");
                return;
            }
            DateTime sTime = string.IsNullOrEmpty(startTime.Text) ? (new DateTime(1900, 12, 12)) : Convert.ToDateTime(startTime.Text);
            DateTime eTime = string.IsNullOrEmpty(endTime.Text) ? DateTime.Now.AddDays(1) : Convert.ToDateTime(endTime.Text).AddDays(1);

            //if(!string.IsNullOrEmpty(startTime.Text)&&! string.IsNullOrEmpty(endTime.Text))
            BindDisseratationNews(sTime, eTime, NewsPager.StartRecordIndex - 1, NewsPager.EndRecordIndex);
            //else
            //    BindDisseratationNews(DateTime.MinValue, DateTime.MinValue, NewsPager.StartRecordIndex-1, NewsPager.EndRecordIndex);      
        }

        /// <summary>
        /// 添加参考文件
        /// </summary>
        protected void AddSpecial_Click(object sender, EventArgs e)
        {
            Response.Redirect("../Reference/Edit.aspx");
        }

        /// <summary>
        /// 修改参考文件"
        /// </summary>
        protected void SettingSort_Click(object sender, EventArgs e)
        {
            string disID = string.Empty;
            if (ViewState["DissNumber"].ToString() == "0")
                disID = disID1.Value;
            else if (int.Parse(ViewState["DissNumber"].ToString()) ==26)
                disID = willHiddenField.Value;
            else
                disID = oneHiddenField.Value;
            Response.Redirect("../Reference/Edit.aspx?ID=" + disID + "&WEBID=" + selectWeb.SelectedValue+"&PageIndex=1");
        }

        /// <summary>
        /// 修改参考文件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Cancel_Click(object sender, EventArgs e)
        {
            string disID = string.Empty;
            if (ViewState["DissNumber"].ToString() == "1")
                disID = oneHiddenField.Value;
            else if (int.Parse(ViewState["DissNumber"].ToString()) ==26)
                disID = willHiddenField.Value;
            else
                disID = disID1.Value;
            Response.Redirect("../List.aspx?WEBID=" + selectWeb.SelectedValue + "&PageIndex=1");//ID=" + disID + "&WEBID=" + selectWeb.SelectedValue);
        }
    }
}
//<asp:ListBox ID="ColumnList" runat="server" Rows="5" Width="150px" ondblclick='deleteItem()'></asp:ListBox>